﻿@{
    ViewBag.Title = "Company Maintenance";
    ViewBag.BackUrl = Url.Action("Index", "Company");
    LineFocus.Nikcron.Models.Lookup States = ViewBag.States;
    LineFocus.Nikcron.Models.Lookup Countries = ViewBag.Countries;
}

@model Nickron.Database.Company

@using (Html.BeginForm("Maintenance", "Company", FormMethod.Post, new { onsubmit = "return ValidateForm();" }))
{
    <div class="col-md-6">

        <div class="box box-danger">
            <div class="box-body">

                <div class="form-group">
                    <label> Company Name:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i></i>
                        </div>
                        <input id="Name" name="Name" maxlength="250" type="text" class="form-control" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->


                <div class="form-group">
                    <label> Contact Person Name:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <input id="ContactPerson" name="ContactPerson" maxlength="250" type="text" class="form-control" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->
                <div class="form-group">
                    <label> Address Line 1:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <input id="Address1" name="Address1" maxlength="500" class="form-control" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">
                    <label> Address Line 2:</label>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <input id="Address2" name="Address2" maxlength="500" class="form-control" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">
                    <label> City/Town/District:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <input id="City" name="City" maxlength="250" type="text" class="form-control" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">
                    <label> Zip:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <input id="Zip" name="Zip" type="text" maxlength="6" class="form-control" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">
                    <label> State:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i></i>
                        </div>
                        <select id="State" name="State" class="selectpicker" title="Select the State">
                            @Html.Partial("SelectList", States)
                        </select>
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">
                    <label> Country:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i></i>
                        </div>
                        <select id="Country" name="Country" class="selectpicker" title="Select the Country">
                            @Html.Partial("SelectList", Countries)
                        </select>
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

            </div><!-- /.box-body -->
        </div><!-- /.box -->
    </div><!-- /.col (left) -->
    <div class="col-md-6">
        <div class="box box-primary">

            <div class="box-body">
                <!-- Date range -->
                <div class="form-group">
                    <label> Mobile Number 1:</label>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <input id="Mobile1" name="Mobile1" type="number" maxlength="10" class="form-control pull-right" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">
                    <label> Mobile Number 2:</label>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <input id="Mobile2" name="Mobile2" type="number" maxlength="10" class="form-control pull-right" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">
                    <label> Phone Number:</label>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i></i>
                        </div>
                        <input id="Phone1" name="Phone1" type="text" maxlength="11" class="form-control pull-right" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">
                    <label> Email ID:</label>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i></i>
                        </div>
                        <input id="Email" name="Email" type="email" maxlength="250" class="form-control pull-right" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">
                    <label> Web:</label>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i></i>
                        </div>
                        <input id="Website" name="Website" maxlength="250" type="text" class="form-control pull-right" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->


                <div class="form-group">
                    <label> User Name:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i></i>
                        </div>
                        <input id="Username" name="Username" maxlength="50" type="text" class="form-control pull-right" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">
                    <label> Password:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i></i>
                        </div>
                        <input id="Password" name="Password" maxlength="50" type="text" class="form-control pull-right" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">
                    @*<div class="checkbox">
                            <label>
                                <input type="checkbox" id="checkStatus" />
                                Status
                            </label>
                        </div>*@

                </div><!-- /.form group -->

            </div><!-- /.box-body -->
        </div><!-- /.box -->

        <div class="box box-success">
            <div class="box-footer">
                <input type="hidden" name="Id" id="Id" value="@ViewBag.Id" />
                <button type="submit" class="btn btn-primary" style=" width:80px;">Save</button>
                <button type="reset" class="btn btn-primary" style=" width:80px;">Cancel</button>
            </div>
        </div><!-- /.box -->
    </div><!-- /.col (right) -->
}

<script type="text/javascript">
    function ValidateForm() {
        RequiredTextbox("Name", "Enter the Company Name");
        RequiredTextbox("ContactPerson", "Enter the Contact Person");
        RequiredTextbox("Address1", "Enter the Address");
        RequiredTextbox("City", "Enter the City");
        RequiredTextbox("Zip", "Enter the Zip");
        ValidateZip("Zip", "Enter Valid Zip");
        RequiredDropdown("State", -1, "Select a State");
        RequiredDropdown("Country", -1, "Select a Country");
        ValidateMobilenumber("Mobile1", "Mobilenumber 1 - Enter Valid Number");
        ValidateMobilenumber("Mobile2", "Mobilenumber 2 - Enter Valid Number");
        ValidatePhonenumber("Phone1", "Enter Valid Phone Number");
        ValidateEmailaddress("Email", "Enter Valid Email Id");
        if("@ViewBag.Id" == "")
        {
            RequiredTextbox("Username", "Enter the Username");
            RequiredTextbox("Password", "Enter the Password");
            ValidMinLength("Username", 6, "Username must be minimum 6 characters");
            ValidMinLength("Password", 6, "Password must be minimum 6 characters");
        }
        return AlertError();
    }

    function AutoCompleteCity()
    {
        $("#City").autocomplete({
            source: function (request, response) {
                var cities = new Array();
                $.ajax({
                    async: false,
                    cache: false,
                    type: "POST",
                    url: "@Url.Action("GetCities", "Master")",
                    data: { "Name": request.term },
                success: function (data) {
                    for (var i = 0; i < data.length ; i++) {
                        cities[i] = { label: data[i].Name, Id: data[i].Id };
                    }
                }
            });
        response(cities);
        },
        select: function (event, ui) {
            $.ajax({
                cache: false,
                async: false,
                type: "POST",
                url: "@(Url.Action("GetStateCountry", "Master"))",
                data: { "CityId": ui.item.Id },
            success: function (data) {
                $('select#State').selectpicker("val", data[0].StateName);
                $('select#Country').selectpicker("val",data[0].CountryName);
            },
            error: function (xhr, ajaxOptions, thrownError) {
            }
        });
        }
        });
    }

    $(document).ready(function () {
        $(".selectpicker").selectpicker();
        AutoCompleteCity();
        if("@ViewBag.Id" != "")
        {
            $('#Id').val('@Model.Id');
            $('#Name').val("@Model.Name");
            $('#ContactPerson').val("@Model.ContactPerson");
            $('#Address1').val("@Model.Address.Address1");
            $('#Address2').val("@Model.Address.Address2");
            $('#City').val("@Model.Address.City");
            $('#Zip').val("@Model.Address.Zip");
            $('#State').selectpicker("val", "@Model.Address.State");
            $('#Country').selectpicker("val", "@Model.Address.Country");
            $(".selectpicker").selectpicker("refresh");
            $('#Mobile1').val("@Model.Contact1.Mobile");
            $('#Mobile2').val("@Model.Contact2.Mobile")
            $('#Phone1').val("@Model.Contact1.Phone")
            $('#Phone2').val("@Model.Contact2.Phone")
            $('#Email').val("@Model.Contact1.Email");
            $('#Website').val("@Model.Contact1.Website");
            $('.form-group:contains("User Name")').closest("div").hide();
            $('.form-group:contains("Password")').closest("div").hide();
        }
    })
</script>
